const mongoose = require('mongoose');
var express = require('express')
var stage = express()

const {createResponse}= require("../../util/createResponse/index");
const {businessCodes}= require("../../code/businessCodes/index");
const {stageService } = require('../../service/impl/stageService/index');

/* 

// router.post('/post/stage/add', (req,res) => {
//   controller.stageController.getSigleIns().create(req,res)
// })
// // V02-根据赛季id,删除赛季
// router.post('/post/stage/delete', (req,res) => {
//   controller.stageController.getSigleIns().findByIdAndRemove(req,res)
// })
// // V03-根据赛季id,修改赛季
// router.post('/post/stage/update', (req,res) => {
//   controller.stageController.getSigleIns().findByIdAndUpdate(req,res)
// })
// router.post('/post/stage/query', (req,res) => {
//   controller.stageController.getSigleIns().queryAll(req,res)
// })
*/
stage.post('/post/stage/add', async (req,res) => {
  let result
  try {
    let news  = req.body.news
    result =  await stageService.getIns().create(news)
  } catch (error) {
    console.log(error);
    createResponse(res,500,businessCodes.b2)
    return
  }
    createResponse(res,200,businessCodes.b1,result)
  })
  
  stage.post('/post/stage/delete', async (req,res) => {
    let result
    try {
      let  id  = req.body.conditions.id
      result =  await stageService.getIns().findByIdAndDelete(id)
    } catch (error) {
      console.log(error);
      createResponse(res,500,businessCodes.b2)
      return
    }
    createResponse(res,200,businessCodes.b1,result)
  })
  
  stage.post('/post/stage/update', async (req,res) => {
    let result
    try {
      let  id  = req.body.conditions.id
      let updates = req.body.updates
      result =  await stageService.getIns().findByIdAndUpdate(id,updates)
    } catch (error) {
      console.log(error);
      createResponse(res,500,businessCodes.b2)
      return
    }
    createResponse(res,200,businessCodes.b1,result)
  })
  
  stage.post('/post/stage/query', async (req,res) => {
    let result
    try {
      result =  await stageService.getIns().find()
    } catch (error) {
      console.log(error);
      createResponse(res,500,businessCodes.b2)
      return
    }
    createResponse(res,200,businessCodes.b1,result)
  })
  
  module.exports= stage